﻿using System;
using System.Windows.Forms;

namespace BTVPodcatcherNamespace
{
    public partial class ProgramSetupForm : Form
    {
        public ProgramSetupForm()
        {
            InitializeComponent();
            updateFeedAmount.Maximum = int.MaxValue / 60000;
            numericUpDown3.Maximum = int.MaxValue;
            
        }
        public void loadSettings()
        {
            BTVServer.Text = ((MainForm)this.MdiParent).BTVServer;
            BTVPort.Text = ((MainForm)this.MdiParent).BTVPort;
            BTVUsername.Text = ((MainForm)this.MdiParent).BTVUsername;
            BTVPassword.Text = ((MainForm)this.MdiParent).BTVPassword;
            updateFeedAmount.Value = ((MainForm)this.MdiParent).updateTimerAmount;
            numericUpDown1.Value = ((MainForm)this.MdiParent).writeMediaInfoAfter;
            numericUpDown2.Value = ((MainForm)this.MdiParent).maxWriteAmount;
            if (((MainForm)this.MdiParent).useTempFiles)
            {
                UseTmpFiles.SelectedIndex = 0;
            }
            else
            {
                UseTmpFiles.SelectedIndex = 1;
            }
            if (((MainForm)this.MdiParent).showWhenMinimzied)
            {
                comboBox1.SelectedIndex = 0;
            }
            else
            {
                comboBox1.SelectedIndex = 1;
            }
            if (((MainForm)this.MdiParent).useSSL)
            {
                comboBox2.SelectedIndex = 0;
            }
            else
            {
                comboBox2.SelectedIndex = 1;
            }
            numericUpDown3.Value = ((MainForm)this.MdiParent).throtlleAmount;
            dateTimePicker1.Value = Convert.ToDateTime(((MainForm)this.MdiParent).startTime.ToString());
            dateTimePicker2.Value = Convert.ToDateTime(((MainForm)this.MdiParent).stopTime.ToString());

            if (((MainForm)this.MdiParent).setFilesToReadOnly)
            {
                comboBox4.SelectedIndex = 0;
            }
            else
            {
                comboBox4.SelectedIndex = 1;
            }

            if (((MainForm)this.MdiParent).useUnsafeHTMLHeaderParsing)
            {
                comboBox5.SelectedIndex = 0;
            }
            else
            {
                comboBox5.SelectedIndex = 1;
            }
            
        }

        

       

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bool b = true;
            if(UseTmpFiles.SelectedIndex==1)
            {
                b=false;
            }
            bool b2 = true;
            if (comboBox1.SelectedIndex == 1)
            {
                b2 = false;
            }
            bool b3 = true;
            if (comboBox2.SelectedIndex == 1)
            {
                b3 = false;
            }
            bool b4 = true;
            if (comboBox4.SelectedIndex == 1)
            {
                b4 = false;
            }
            bool b5 = true;
            if (comboBox5.SelectedIndex == 1)
            {
                b5 = false;
            }
            ((MainForm)MdiParent).loadSettings(BTVServer.Text.Trim(), BTVPort.Text.Trim(), BTVUsername.Text, BTVPassword.Text, (int)updateFeedAmount.Value, (int)numericUpDown1.Value, (int)numericUpDown2.Value, b, b2, (int)numericUpDown3.Value,dateTimePicker1.Value.TimeOfDay, dateTimePicker2.Value.TimeOfDay, b3,b4,b5);
            this.Close();
        }

        
    }
}
